var cyb = cyb || {};
cyb.init = {
    d: {
        isHomeReady: false,//首页是否已加载
        myPhone: '',//用户手机
        userType: '',//用户角色
        pageSize: 20,//一页20条
        page_0: 1,//默认列表第一页
        page_1: 1,//默认列表第一页
        loadTab0End: false,//第一页数据都加载完了
        loadTab1End: false//第二页数据都加载完了
    },
    i: function () {
        this.page.i();
        this.btn.i();
        cyb.init.d.isHomeReady = true;
    },
    page: {
        i: function () {
            var t = this;
            // t.ready();
            t.dev();
        },
        redirect: function () {
            var _t = this;
            var _token = _t.getCookie("Y3liZXJzcGF7ZV9jb2Rl");
            if (!_token) {
                IyData.OAuth();
            } else {
                if (_token.indexOf(md5(cyb.init.d.myPhone)) < 0)
                    _t.setCookie('Y3liZXJzcGF7ZV9jb2Rl', md5(cyb.init.d.myPhone) + _token, 100);
                _t.com();
            }
        },
        getCookie: function (key) {
            var ck = document.cookie.split("; ");
            for (var i = 0; i < ck.length; i++) {
                var ci = ck[i].split('=');
                if (ci[0] == key) {
                    if (ci.length > 1) {
                        return decodeURI(ci[1])
                    } else {
                        return ""
                    }
                }
            }
            return ""
        },
        setCookie: function (name, value, days) { //设置cookie
            var d = new Date();
            d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "expires=" + d.toUTCString();
            document.cookie = name + "=" + value + "; " + expires;
        },
        ready: function () {
            var _t = this;
            vrv.init({
                debug: false
            });
            vrv.ready(function () {
                vrv.jssdk.showNavigationBar({
                    show: false
                });
                vrv.jssdk.getAccountInfo({
                    success: function (r) {
                        cyb.init.d.userID=r.mUserId;
                        _t.com();
                    }
                });
            });
        },
        dev: function () {
            //cyb.init.d.myPhone = '15200000006';//'15100000007';
            cyb.init.d.userID=2;
            this.com();
        },
        com: function () {
            $('.iy-home-bd').append($('#home').html());
            IyData.getUserType(cyb.init.d.userID, function (type) {//获取角色类型
                sessionStorage.setItem('urlVal', JSON.stringify({userInfo: cyb.init.d.userInfo}));
                cyb.init.d.userType = type;
                var nd = {type: type};
                $('.iy-nav').empty().append(JsTpl().render(nd, 'nav'));
                $('.iy-body').empty().append((type == 5 || type == 7 || type == 8) ? $("#iyBody1").html() : $("#iyBody").html());
                cyb.init.btn.touch();//初始化滚动加载
                if (type != 5 && type != 7 && type != 8) {//当有预警时,默认加载预警数据
                    IyData.getWarnList(function (r) {
                        var warn = $('.iy-list-warn');
                        warn.empty().append(JsTpl().render(r, 'warnListItem'));
                    }, 1, cyb.init.d.$touch);
                    IyData.getWarnNum(function (warn) {
                        //获取风险数量
                        var htp = $('.iy-header-tip');
                        htp.empty().append(JsTpl().render(warn, 'warn'));
                        setTimeout(function () {
                            htp.addClass('iy-ready');
                        }, 10);
                    });
                }
                IyData.getShowCount(function (count) {//获取待办数量
                     //en = count["expertInfoNum"] > 99 ? 99 : count["expertInfoNum"],
                    var pe = count["pendingEvent"] > 99 ? 99 : count["eventNum"],
                        pw = count["pendingWarning"] > 99 ? 99 : count["riskNum"],
                        pr = count["pendingReport"] > 99 ? 99 : count["dailyReportNum"],
                        pn = count["pendingNewsFlash"] > 99 ? 99 : count["todayBulletinNum"];

                    //en == 0 ? $('.iy-expertInfoNum .iy-nav-tips').empty() : $('.iy-expertInfoNum .iy-nav-tips').empty().append('<em class="iy-nav-num">' + en + '</em>');
                    pe == 0 ? $('.iy-pendingEvent .iy-nav-tips').empty() : $('.iy-pendingEvent .iy-nav-tips').empty().append('<em class="iy-nav-num">' + pe + '</em>');
                    pw == 0 ? $('.iy-pendingWarning .iy-nav-tips').empty() : $('.iy-pendingWarning .iy-nav-tips').empty().append('<em class="iy-nav-num">' + pw + '</em>');
                    pr == 0 ? $('.iy-pendingReport .iy-nav-tips').empty() : $('.iy-pendingReport .iy-nav-tips').empty().append('<em class="iy-nav-num">' + pr + '</em>');
                    pn == 0 ? $('.iy-pendingNewsFlash .iy-nav-tips').empty() : $('.iy-pendingNewsFlash .iy-nav-tips').empty().append('<em class="iy-nav-num">' + pn + '</em>');
                });
            });
        },
        refresh: function (me) {
            //拉取预警数量
            IyData.getWarnNum(function (warn) {//获取风险数量
                var htp = $('.iy-header-tip');
                htp.find('.iht-c-red').text(warn['red']);
                htp.find('.iht-c-orange').text(warn['orange']);
                htp.find('.iht-c-yellow').text(warn['yellow']);
                htp.find('.iht-c-blue').text(warn['blue']);
                htp.find('.iht-c-gray').text(warn['none']);
            });
            //刷新待办条数
            IyData.getShowCount(function (count) {//获取待办数量
                var pe = count["pendingEvent"] > 99 ? 99 : count["eventNum"],
                    pw = count["pendingWarning"] > 99 ? 99 : count["riskNum"],
                    pr = count["pendingReport"] > 99 ? 99 : count["dailyReportNum"],
                    pn = count["pendingNewsFlash"] > 99 ? 99 : count["todayBulletinNum"];
                pe == 0 ? $('.iy-pendingEvent .iy-nav-tips').empty() : $('.iy-pendingEvent .iy-nav-tips').empty().append('<em class="iy-nav-num">' + pe + '</em>');
                pw == 0 ? $('.iy-pendingWarning .iy-nav-tips').empty() : $('.iy-pendingWarning .iy-nav-tips').empty().append('<em class="iy-nav-num">' + pw + '</em>');
                pr == 0 ? $('.iy-pendingReport .iy-nav-tips').empty() : $('.iy-pendingReport .iy-nav-tips').empty().append('<em class="iy-nav-num">' + pr + '</em>');
                pn == 0 ? $('.iy-pendingNewsFlash .iy-nav-tips').empty() : $('.iy-pendingNewsFlash .iy-nav-tips').empty().append('<em class="iy-nav-num">' + pn + '</em>');
            });
            //重置
            cyb.init.d['page_0'] = 1;
            cyb.init.d['page_1'] = 1;
            cyb.init.d.loadTab0End = false;
            cyb.init.d.loadTab1End = false;
            cyb.init.d.loadingHome = false;
            cyb.init.d.loadingWarn = false;
            //刷新列表
            IyData.homeList(function (r) {
                var home = $('.iy-list-home');
                home.empty().append(JsTpl().render(r, 'homeListItem'));
            }, 1, me);
            if (cyb.init.d.userType != 5 && cyb.init.d.userType != 7 && cyb.init.d.userType != 8) {//当有预警时,默认加载预警数据
                IyData.getWarnList(function (r) {
                    var warn = $('.iy-list-warn');
                    warn.empty().append(JsTpl().render(r, 'warnListItem'));
                }, 1, me);
            }
            me.resetload();
            me.unlock();//解锁
            me.noData(false);
        }
    },
    btn: {
        i: function () {
            this.scroll();
            this.view();
        },
        view: function () {
            var _t = this;
            IyBaseFun.e.$Body.on('click', function () {
                IyBaseFun.e.$Body.removeClass('noScroll');
                _t.toAddClose();
            })
        },
        getEvent: function () {
            return window.event || arguments.callee.caller.arguments[0];
        },
        toAddClose: function () {
            $('.addList-tip').removeClass('show');
            setTimeout(function () {
                $('.addList-tip').remove();
            }, 300)
        },
        touch: function () {
            cyb.init.d.$touch = $('.iy-home-bd').dropload({
                scrollArea: $('.iy-home'),
                domDown: {
                    domClass: 'homeDown'
                },
                loadUpFn: function (me) {
                    cyb.init.page.refresh(me);
                },
                loadDownFn: function (me) {
                    switch (IyBaseData.data.tabHome_tab) {
                        case 0:
                            if (!cyb.init.d.loadTab0End && !cyb.init.d.loadHomeError && !cyb.init.d.loadingHome) {
                                cyb.init.d.loadingHome = true;
                                IyData.homeList(function (r) {
                                    var home = $('.iy-list-home');
                                    if (cyb.init.d['page_0'] == 1) {
                                        home.empty()
                                    }
                                    home.append(JsTpl().render(r, 'homeListItem'));
                                    cyb.init.d.loadingHome = false;
                                }, cyb.init.d['page_0'], me);
                            }
                            break;
                        case 1:
                            if (!cyb.init.d.loadTab1End && !cyb.init.d.loadWarnError && !cyb.init.d.loadingWarn) {
                                cyb.init.d.loadingWarn = true;
                                IyData.getWarnList(function (r) {
                                    var warn = $('.iy-list-warn');
                                    if (cyb.init.d['page_1'] == 1) {
                                        warn.empty()
                                    }
                                    warn.append(JsTpl().render(r, 'warnListItem'));
                                    cyb.init.d.loadingWarn = false;
                                }, cyb.init.d['page_1'], me);
                            }
                            break;
                    }
                },
                threshold: 50
            });
        },
        scroll: function () {
            $('.iy-home').scroll(function () {
                var $ib = $('.iy-body');
                var bt = $ib.position().top;
                if ($('.iy-home').scrollTop() >= bt) {
                    $ib.addClass('iy-fixed');
                } else {
                    $ib.removeClass('iy-fixed');
                }
            })
        },
        toDesc: function (id, isHome) {
            var uType = cyb.init.d.userType;
            if (isHome && (uType == 5 || uType == 6 || uType == 7 || uType == 8)) {
                sessionStorage.setItem('descID', id);
                sessionStorage.setItem('descSim', '1');
                window.location.hash = '#Desc';
                // IyData.getPush(id, function (code) {
                //     if (code == 1) {
                //         sessionStorage.setItem('descID', id);
                //         sessionStorage.setItem('descSim', '1');
                //         window.location.hash = '#Desc';
                //     } else {
                //         comNotice.init('值班员已取消推送');
                //         $('.il-item[data-id="' + id + '"]').remove();
                //     }
                // });
            } else {
                sessionStorage.setItem('descID', id);
                sessionStorage.setItem('descSim', '1');
                window.location.hash = '#Desc';
            }
        },
        toDesc2: function (key, temType) {//-----------------------------------------跳转
            var tt = temType || 3;
            // window.location.href = '/Cyberspace/messageManager.html?temType=' + tt + '&enterType=3&businesskey=' + key;
            window.location.href = '../york/phone/messageManager.html#/details?id='+key;
        },
        toAdd: function () {
            window.location.hash = '#AddHome'
        },
        toList: function () {
            window.location.hash = '#List';
        },
        toReport: function () {
            window.location.hash = '#Report';
        },
        toOther: function (txt, header, type, url) {
            sessionStorage.setItem('header', txt);
            sessionStorage.setItem('urlType', type);
            sessionStorage.setItem('details_header', header);
            window.location.href = '/Cyberspace/' + url;
        }
    },
    backHome: function () {
        if (!cyb.init.d.isHomeReady) {
            cyb.init.i();//加载首页
        }
        cyb.common.toExit('iy-home');//返回首页
        cyb.toList.reset();//因没有刷新,列表默认数据都要重置
        cyb.report.reset();
        cyb.report.d.isTab = 0;
        cyb.toList.d.isListReady = false;
        cyb.toList.d.isTab = 0;
        cyb.desc.d.isDescPage = false;//取消详情标记
        cyb.sum.d.isSumPage = false;
        cyb.add.d.isAddPage = false;//取消上报标记
        cyb.addHome.reset();//重置上报首页数据
        cyb.add.reset();//重置上报数据
        cyb.sum.reset();
        sessionStorage.removeItem('descSim');
    }
};

cyb.common = {
    toJoin: function (pageA, pageB, c) {
        $('.' + pageA).addClass('toHide').animate({'left': "-45%"}, 500);
        $('.' + pageB).addClass('toShow').animate({"left": 0}, 500);
        c ? c() : "";
    },
    toExit: function (pageA, pageB) {
        $('.' + pageA).animate({'left': 0}, 500).removeClass('toHide');
        if (pageB) {
            $('.' + pageB).css("z-index", "9999").animate({'left': "100%"}, 500).removeClass('toShow');
            setTimeout(function () {
                $('.' + pageB).remove();
            }, 500)
        } else {
            $('.iy-secPage').animate({'left': "100%"}, 500).removeClass('toShow');
            setTimeout(function () {
                $('.sec-header').empty();
                $('.sec-body').empty();
            }, 500)
        }
    }
};

cyb.desc = {//详情方法
    d: {
        isDescPage: false,
        grade1: ['', '很高', '高', '中等', '低', '很低'],
        grade2: ['', '特别重大', '重大', '较大', '一般', '其他']
    },
    i: function (id) {
        $('.sec-header').empty().append($('#descHeader').html());
        $('.sec-body').append($('#Desc').html());
        cyb.desc.d.isDescPage = true;
        if ($('.iy-work').length > 0) {
            cyb.common.toJoin('iy-work', 'iy-desc', function () {
                IyData.getDesc(id, function (d) {
                    d.descSim = '';
                    $('.iy-desc .desc-bd').empty().append(JsTpl().render(d, 'descPage'));
                });
            });
        } else if ($('.mod-addHome').length > 0) {
            cyb.common.toJoin('mod-addHome', 'iy-desc', function () {
                IyData.getDesc(id, function (d) {
                    d.descSim = '';
                    $('.iy-desc .desc-bd').empty().append(JsTpl().render(d, 'descPage'));
                });
            });
        } else {
            cyb.common.toJoin('iy-home', 'iy-secPage', function () {
                $('.iy-desc').css('left', 0);
                IyData.getDesc(id, function (d) {
                    d.descSim = sessionStorage.getItem('descSim') || '';
                    $('.iy-desc .desc-bd').empty().append(JsTpl().render(d, 'descPage'));
                });
            });
        }
    },
    j: function (id) {
        $('.sec-header').empty().append($('#descHeader').html());
        $('.sec-body').append($('#Desc').html());
        $('.iy-secPage').css('left', 0).addClass('toShow');
        $('.iy-desc').css('left', 0);
        cyb.desc.d.isDescPage = true;
        IyData.getDesc(id, function (d) {
            d.descSim = sessionStorage.getItem('descSim') || '';
            $('.iy-desc .desc-bd').empty().append(JsTpl().render(d, 'descPage'));
            //当详情已经加载完成，偷偷加载首页
            $('.iy-home').css('left', '-45%');
            cyb.init.i();
        });
    }
};

cyb.report = {
    d: {
        page_0: 1,
        page_1: 1,
        pageSize: 20,
        isTab: 0//当前选中
    },
    reset: function () {
        cyb.report.d['loadList0'] = false;
        cyb.report.d['loadList1'] = false;
        cyb.report.d['loadError0'] = false;
        cyb.report.d['loadError1'] = false;
        cyb.report.d['loadIngList'] = false;
        cyb.report.d['loadEndList'] = false;
        cyb.report.d['page_0'] = 1;
        cyb.report.d['page_1'] = 1;
    },
    i: function () {
        var sVal = sessionStorage.getItem('urlVal');
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        cyb.init.d.userID=cyb.init.d.userInfo['createUserInfo']['linkdoodID'];
        cyb.report.reset();
        //填充静态
        $('.sec-header').empty().append($('#headerReport').html());
        $('.sec-body').append($('#reportPage').html());
        cyb.common.toJoin('iy-home', 'iy-secPage');
        this.touch();
        //加载办结列表
        IyData.gerReport(1, function (r) {
            $('.rList-end-list').append(JsTpl().render(r, 'rItem_1'));
        }, cyb.report.d.$touch, 1);
        //this.getDept();
    },
    j: function () {
        var sVal = sessionStorage.getItem('urlVal');
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        cyb.init.d.userID=cyb.init.d.userInfo['createUserInfo']['linkdoodID'];
        cyb.report.reset();
        //填充静态
        $('.sec-header').empty().append($('#headerReport').html());
        $('.sec-body').append($('#reportPage').html());
        $('.iy-secPage').css('left', 0);
        this.touch();
        //this.getDept();
        //加载办结列表
        IyData.gerReport(1, function (r) {
            $('.rList-end-list').append(JsTpl().render(r, 'rItem_1'));
        }, cyb.report.d.$touch, 1);
    },
    refresh: function (me, c) {
        //参数重置
        cyb.report.reset();

        IyData.gerReport(0, function (r) {
            $('.rList-ing-list').empty().append(JsTpl().render(r, 'rItem_0'));
        }, me, 1);
        IyData.gerReport(1, function (r) {
            $('.rList-end-list').empty().append(JsTpl().render(r, 'rItem_1'));
        }, me, 1);
        c ? c() : ""
    },
    touch: function () {
        cyb.report.d.$touch = $('.rList-scroll').dropload({
            scrollArea: $('.rContent'),
            domDown: {
                domClass: 'reportDown'
            },
            loadUpFn: function (me) {
                cyb.report.refresh(me, function () {
                    me.resetload();
                });
            },
            loadDownFn: function (me) {
                switch (cyb.report.d.isTab) {
                    case 0:
                        if (!cyb.report.d['loadList0'] && !cyb.report.d['loadError0'] && !cyb.report.d['loadIngList']) {
                            cyb.report.d['loadIngList'] = true;
                            IyData.gerReport(0, function (r) {
                                $('.rList-ing-list').append(JsTpl().render(r, 'rItem_0'));
                                cyb.report.d['loadIngList'] = false;
                            }, me, cyb.report.d.page_0);
                        }
                        break;
                    case 1:
                        if (!cyb.report.d['loadList1'] && !cyb.report.d['loadError1'] && !cyb.report.d['loadEndList']) {
                            cyb.report.d['loadEndList'] = true;
                            IyData.gerReport(1, function (r) {
                                $('.rList-end-list').append(JsTpl().render(r, 'rItem_1'));
                                cyb.report.d['loadEndList'] = false;
                            }, me, cyb.report.d.page_1);
                        }
                        break;
                }
            },
            threshold: 50
        });
    },
    getDept: function () {
        IyData.getDept(cyb.report.d.phone, function (r) {
            cyb.report.d['submitUnit'] = r['DEPT_NAME'];
            cyb.report.d['submitUnitId'] = r['DEPT_ID'];
            cyb.report.d['onDutyPerson'] = r['USER_NAME'];
        })
    },
    desc2: {
        d: {},
        i: function () {
            this.d.isDesc2 = true;
            this.d.fid = getUrlParam.get('id');
            //this.dev();
            this.ready();
        },
        ready: function () {
            var _t = this;
            vrv.init({
                debug: false
            });
            vrv.ready(function () {
                vrv.jssdk.showNavigationBar({
                    show: false
                });
                vrv.jssdk.getAccountInfo({
                    success: function (r) {
                        cyb.init.d.userID=r.mUserId;
                        _t.com();
                    }
                });
            });
        },
        dev: function () {
            var _t = this;
            cyb.init.d.userID=2;
            _t.com();
        },
        com: function () {
            $('.iy-secPage').addClass('toShow').css('left', 0);
            var header = $('.sec-header'), td = this.d;
            header.empty().append($('#headerReportDesc').html());

            IyData.getUserType(cyb.init.d.userID, function () {//获取角色类型
                sessionStorage.setItem('urlVal', JSON.stringify({userInfo: cyb.init.d.userInfo}));
                IyData.getReportDesc(td.fid, function (r) {
                    var fd=$.extend(true,{},cyb.init.d.userInfo,r.dailyReport);
                    $('.sec-body').append(JsTpl().render({type:r.isSubmit}, 'reportForm'));
                    $('.reportForm').css('left', 0);
                    $('.reportForm-bd').append(JsTpl().render(fd, 'formContent'));
                    if (r.isSubmit == 0) {
                        header.find('.mh-bd').text('情况报告');
                        var fd = {
                            userID:cyb.init.d.userID,
                            fid: td.fid,
                            fillTime: new Date().Format('yyyy-MM-dd hh:mm:ss')
                        };
                        $('.rfBody').empty().append(JsTpl().render(fd, 'form_0'))
                    } else {
                        header.find('.mh-bd').text('反馈详情');
                        $('.rfBody').empty().append(JsTpl().render(r, 'form_1'))
                    }
                });
            });
        }
    },
    btn: {
        i: function () {
            this.view();
        },
        view: function () {
            IyBaseFun.e.$Body.on('click', '.rTab a', function () {
                if (!$(this).hasClass('active')) {
                    $(this).addClass('active').siblings().removeClass('active');
                    var idx = $(this).index();
                    cyb.report.d.isTab = idx;
                    $('.rContent').find('.rList-box').eq(idx).addClass('active').siblings().removeClass('active');
                    if (!cyb.report.d['loadList' + idx]) {
                        cyb.report.d.$touch.unlock();//解锁
                        cyb.report.d.$touch.noData(false);
                    } else {
                        cyb.report.d.$touch.lock('down');//锁
                        cyb.report.d.$touch.noData();
                    }
                    cyb.report.d.$touch.resetload();
                }
            });
            IyBaseFun.e.$Body.on('click', '.btn-ms-sure[data-bclick="sysSelect"]', function () {
                var ck = $('.ms-wrap').find('.active');
                $('input[name="systemSituation"]').val(ck.text());
                $('.sysText').text(ck.text());
                $('.btn-ms-cancel').click();
            });
            IyBaseFun.e.$Body.on('input', '.ipt-only-num', function () {
                $(this).val($(this).val().replace(/[^\d]/g, ''));
            });
        },
        toAdd: function () {
            cyb.init.btn.getEvent().stopPropagation();
            IyBaseFun.e.$Body.addClass('noScroll').append($('#addList').html());
            setTimeout(function () {
                $('.addList-tip').addClass('show');
            }, 10);
        },
        back: function () {
            $('.sec-header').empty().append($('#headerReport').html());
            cyb.common.toExit('mod-report', 'reportForm');
        },
        sysSelect: function () {
            var op = [['正常', '异常']];
            comSelect.init(op, 'sysSelect');
        },
        toSubmit: function () {
            var flag = true;
            $.each($('.saveForm').find('.required'), function (i, v) {
                if ($(v).val() == '') {
                    comNotice.init($(v).data('name') + '不能为空');
                    flag = false;
                    return false
                }
            });
            if (!flag) return;

            IyData.postReport($('.saveForm').serialize(), function () {
                if (cyb.report.desc2.d.isDesc2) {
                    setTimeout(function () {
                        cyb.report.btn.toClose()
                    }, 500);
                } else {
                    setTimeout(function () {
                        window.location.reload();
                    }, 500)
                }
            });
        },
        toForm: function (type,fid) {
            var header = $('.sec-header');
            header.empty().append($('#headerForm').html());
            if (type == 0) {
                header.find('.mh-bd').text('情况报告');
            } else {
                header.find('.mh-bd').text('反馈详情');
            }
            var nt = {
                type: type
            };
            $('.sec-body').append(JsTpl().render(nt, 'reportForm'));
            cyb.common.toJoin('mod-report', 'reportForm');
            IyData.getReportDesc(fid, function (r) {
                var fd=$.extend(true,{},cyb.init.d.userInfo,r.dailyReport);
                $('.reportForm-bd').append(JsTpl().render(fd, 'formContent'));
                if (r.isSubmit == 0) {
                    var fd = {
                        userID:cyb.init.d.userID,
                        fid: fid,
                        fillTime: new Date().Format('yyyy-MM-dd hh:mm:ss')
                    };
                    $('.rfBody').empty().append(JsTpl().render(fd, 'form_0'))
                } else {
                    $('.rfBody').empty().append(JsTpl().render(r, 'form_1'))
                }
            });
        },
        toClose: function () {
            vrv.jssdk.closeView({});
        }
    }
};
cyb.report.btn.i();

cyb.add = {
    d: {
        isAddPage: false,
        isReady: true,
        infoType: 1,
        noUnit: true,
        submitUnit: '',
        submitUnitId: "",
        onDutyPerson: "",
        selectList: {//下拉列表
            list: [],
            code: [],
            sub: {}//子事件列表
        },
        riskLevel: {
            list: ['很高', '高', '中等', '低', '很低'],
            grade: [1, 2, 3, 4, 5]
        },
        eventLevel: {
            list: ['特别重大', '重大', '较大', '一般', '其他'],
            grade: [1, 2, 3, 4, 0]
        },
        hasCk: {},
        scopeJson: {
            ip: '',
            ym: '',
            url: '',
        },//记录影响
        files: {
            name: [],
            path: []
        },
        hasAreaCk: [],//地域已选
        hasIndustryCk: []
    },
    reset: function () {
        cyb.add.d.hasCk = {};
        cyb.add.d.scopeJson = {
            ip: [],
            ipList: [],
            ym: [],
            ymList: [],
            url: [],
            urlList: []
        };
        cyb.add.d.files = {
            name: [],
            path: []
        };
        cyb.add.d.hasAreaCk = [];
        cyb.add.d.hasIndustryCk = [];
        cyb.add.d.isReady = true;
    },
    i: function () {
        var type = sessionStorage.getItem('infoType'), sVal = sessionStorage.getItem('urlVal'), _t = this;
        cyb.add.d.infoType = type;
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        if (type != 1 && type != 2 && type != 3) {
            type = 1
        }
        //添加静态
        $('.sec-header').empty().append($('#headerAdd').html());
        $('.mh-bd').text(type == 1 ? "信息新增" : (type == 2 ? "风险新增" : "事件新增"));
        $('.sec-body').append($('#createPage').html());
        if ($('.mod-addHome').length > 0) {
            cyb.common.toJoin('mod-addHome', 'mod-create', function () {
                var cd=$.extend(true,{},cyb.init.d.userInfo,{happenTime: new Date().Format('yyyy-MM-dd hh:mm')});
                $('.mod-create').append(JsTpl().render(cd, 'add_' + type));
            });
        } else {
            cyb.common.toJoin('iy-home', 'iy-secPage', function () {
                var cd=$.extend(true,{},cyb.init.d.userInfo,{happenTime: new Date().Format('yyyy-MM-dd hh:mm')});
                $('.mod-create').css('left', 0).append(JsTpl().render(cd, 'add_' + type));
            });
        }
        cyb.add.btn.happenTime();
        if (type == 3) {
            cyb.add.btn.initTime();
        }
        cyb.add.d.isAddPage = true;
        _t.getInfo(type);//获取相关需要信息
    },
    j: function () {
        var type = sessionStorage.getItem('infoType'), sVal = sessionStorage.getItem('urlVal'), _t = this;
        cyb.add.d.infoType = type;
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        if (type != 1 && type != 2 && type != 3) {
            type = 1
        }
        //添加静态
        $('.sec-header').empty().append($('#headerAdd').html());
        $('.mh-bd').text(type == 1 ? "信息新增" : (type == 2 ? "风险新增" : "事件新增"));
        $('.sec-body').append($('#createPage').html());
        $('.iy-secPage').css('left', 0).addClass('toShow');
        var cd=$.extend(true,{},cyb.init.d.userInfo,{happenTime: new Date().Format('yyyy-MM-dd hh:mm')});
        $('.mod-create').css('left', 0).append(JsTpl().render(cd, 'add_' + type));
        cyb.add.btn.happenTime();
        if (type == 3) {
            cyb.add.btn.initTime();
        }
        cyb.add.d.isAddPage = true;
        _t.getInfo(type);//获取相关需要信息
    },
    getInfo: function (type) {
        if (type != 1) {
            cyb.add.d.selectList = {
                list: [],
                code: [],
                sub: {}//子事件列表
            };
            IyData.getType(type);
        }
    },
    btn: {
        i: function () {
            this.view();
        },
        closeTips: function () {
            $('.mod-tips').remove();
            $('.mod-mark').remove();
        },
        toSubmit: function () {//提交
            //cyb.add.d.isUpdate ? IyData.updateInfo($('.createForm').serialize()) : IyData.addInfo($('.createForm').serialize());
            IyData.addInfo(cyb.add.d.infoType,$('.createForm').serialize())
        },
        initTime: function () {
            var opt = {}, ipt = $('.ipt-feedback');
            var t = new Date();
            var currYear = t.getFullYear() - 1;
            opt.datetime = {preset: 'datetime'};
            opt.default = {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                dateFormat: 'yyyy-mm-dd',
                lang: 'zh',
                startYear: currYear, //开始年份
                endYear: currYear + 10
            };
            ipt.mobiscroll($.extend(opt['datetime'], opt['default']));
        },
        happenTime: function () {
            var opt = {}, ipt = $('input[name="happenTime"]');
            var t = new Date();
            var currYear = t.getFullYear();
            opt.datetime = {preset: 'datetime'};
            opt.default = {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                dateFormat: 'yy-mm-dd',
                lang: 'zh',
                endYear: currYear
            };
            ipt.mobiscroll($.extend(opt['datetime'], opt['default']));
        },
        view: function () {
            IyBaseFun.e.$Body.on('click', '.mc-item', function () {
                var $t = $(this), $ipt = $t.find('.mc-ipt'), $area = $t.find('textarea');
                $ipt.focus() && $area.focus();
            });
            IyBaseFun.e.$Body.on('click', '.mc-type li', function () {
                var $t = $(this), $ipt = $t.find('input[type="checkbox"]');
                if ($t.hasClass('checked')) {
                    $t.removeClass('checked');
                    $ipt.prop("checked", false);
                } else {
                    $t.addClass('checked');
                    $ipt.prop("checked", true)
                }
            });
            IyBaseFun.e.$Body.on('click', '.btn-ms-sure[data-bclick="toSelectType"]', function () {
                var idx = $('.ms-wrap').find('.active').index(), td = cyb.add.d.selectList;
                $('.btn-ms-cancel').click();
                $('.mc-risk-show').val(td['list'][idx]);
                $('.mc-risk-hide').val(td['code'][idx]);
            });
            IyBaseFun.e.$Body.on('click', '.btn-ms-sure[data-bclick="toSelectGrade"]', function () {
                var idx = $('.ms-wrap').find('.active').index(), td = cyb.add.d.riskLevel;
                $('.btn-ms-cancel').click();
                $('.mc-grade-show').val(td['list'][idx]);
                $('.mc-grade-hide').val(td['grade'][idx]);
            });
            IyBaseFun.e.$Body.on('click', '.btn-ms-sure[data-bclick="toSelectGrade2"]', function () {
                var idx = $('.ms-wrap').find('.active').index(), td = cyb.add.d.eventLevel;
                $('.btn-ms-cancel').click();
                $('.mc-grade-show').val(td['list'][idx]);
                $('.mc-grade-hide').val(td['grade'][idx]);
            });
            IyBaseFun.e.$Body.on('click', '.btn-ms-sure[data-bclick="toSelectEventType"]', function () {
                //打开子事件类型
                var idx = $('.ms-wrap').find('.active').index(), td = cyb.add.d.selectList;
                $('.mod-select').remove();
                cyb.add.d.hasCk['name'] = [td['list'][idx]];
                cyb.add.d.hasCk['type3'] = td['code'][idx];
                var op = [];
                op.push(td['sub'][td['code'][idx]]['list']);
                comSelect.init(op, "toSelectType2");
            });
            IyBaseFun.e.$Body.on('click', '.btn-ms-sure[data-bclick="toSelectType2"]', function () {
                var idx = $('.ms-wrap').find('.active').index(), td = cyb.add.d.selectList.sub[cyb.add.d.hasCk['type3']];
                cyb.add.d.hasCk['name'].push(td['list'][idx]);
                $('.btn-ms-cancel').click();
                $('.mc-event-show').val(cyb.add.d.hasCk['name'].join('-'));
                $('.mc-event-hide').val(cyb.add.d.hasCk['type3']);
                $('.mc-event-hide2').val(td['code'][idx]);
            });
            IyBaseFun.e.$Body.on('click', '.scList-item', function () {
                var ta = $(this).parent('li');
                if (ta.hasClass('checked')) {
                    ta.removeClass('checked');
                } else {
                    ta.addClass('checked');
                }
            });
        },
        sure: function (state, old, isUpdate) {
            if (isUpdate) {
                cyb.add.d.isUpdate = true;
            } else {
                delete cyb.add.d.isUpdate
            }
            var flag = true;
            $.each($('.required'), function (i, v) {
                var $ipt = $(v), name = $ipt.data('name');
                if ($ipt.val() == '') {
                    comNotice.init(name + '不能为空!');
                    flag = false;
                    return false
                }
            });
            if (!flag) return;
            if (cyb.add.d.infoType == 1) {
                var linkVal = $('.mc-ipt[name="link"]').val().replace(/\s/g, "");
                if (linkVal != '') {
                    if (!Iy.isUrl(Iy.isHttp(linkVal))) {
                        return comNotice.init('链接格式不对');
                    }
                    $('.mc-ipt[name="link"]').val(Iy.isHttp(linkVal));
                }
                var typeInput = $('.mc-ipt-type'), typeArr = [];
                $.each($('.mc-type').find('input[type="checkbox"]:checked'), function (i, v) {
                    typeArr.push($(v).val());
                });
                if (typeArr.length == 0) {
                    return comNotice.init('请勾选类型!');
                }
                typeInput.val(typeArr.join(','));
            }
            var fax = $('.mc-ipt[name="fax"]').val();
            if (fax != '' && cyb.add.d.infoType != 1) {
                if (!Iy.isFax(fax)) {
                    return comNotice.init("传真格式不正确");
                }
            }
            $('input[name="state"]').val(state);
            cyb.add.d.isReady ? IyBaseFun.e.$Body.append($('#tips').html()) : comNotice.init('数据提交处理中,请不要重复提交');
        },
        typeSelect: function () {
            var op = [];
            op.push(cyb.add.d.selectList['list']);
            comSelect.init(op, "toSelectType");
        },
        eventSelect: function () {
            var op = [];
            op.push(cyb.add.d.selectList['list']);
            comSelect.init(op, "toSelectEventType");
        },
        gradeSelect: function () {
            var op = [];
            op.push(cyb.add.d.riskLevel['list']);
            comSelect.init(op, 'toSelectGrade');
        },
        gradeSelect2: function () {
            var op = [];
            op.push(cyb.add.d.eventLevel['list']);
            comSelect.init(op, 'toSelectGrade2');
        },
        scope: function () {
            $('.sec-header').empty().append($('#headerScope').html());
            $('.sec-body').append(JsTpl().render(cyb.add.d.scopeJson, 'scope'));
            cyb.common.toJoin('mod-create', 'mod-scope');
        },
        del: function (t, type) {
            var json = cyb.add.d.scopeJson;
            switch (type) {
                case 1:
                    json['ip']='';
                    break;
                case 2:
                    json['ym']='';
                    break;
                case 3:
                    json['url']='';
                    break;
            }
            $(t).val('');
        },
        addInput: function (t) {
            switch (t) {
                case 1:
                    var ip = $('.ms-ip');
                    if (ip.find('.ipt-input').length != 0) {
                        comNotice.init('有未完成IP,不能新增');
                    } else {
                        ip.append('<li><input class="ipt-input" type="text" placeholder="IP地址示例：127.0.0.1" onblur="cyb.add.btn.addIp(this)"></li>')
                    }
                    break;
                case 2:
                    var ym = $('.ms-ym');
                    if (ym.find('.ipt-input').length != 0) {
                        comNotice.init('有未完成域名,不能新增');
                    } else {
                        ym.append('<li><input class="ipt-input" type="text" placeholder="域名示例：A.gov" onblur="cyb.add.btn.addYm(this)"></li>')
                    }
                    break;
                case 3:
                    var url = $('.ms-url');
                    if (url.find('.ipt-input').length != 0) {
                        comNotice.init('有未完成Url,不能新增');
                    } else {
                        url.append('<li><input class="ipt-input" type="text" placeholder="URL示例：http://www.A.gov/A" onblur="cyb.add.btn.addUrl(this)"></li>')
                    }
                    break;
            }
        },
        addIp: function (t) {
            var _val = $(t).val(), $li = $(t).parent('li');
            cyb.add.d.scopeJson.ip='';
            if(_val!=''){
                if (Iy.isIp(_val)) {
                    cyb.add.d.scopeJson.ip=_val;
                    $li.empty().append('<a href="javascript:;" onclick="cyb.add.btn.del(this,1)" class="btn-del"><i class="ico ico-clear"></i></a><div class="ms-item">' + _val + '</div>');
                } else {
                    cyb.add.d.scopeJson.ip='';
                    $(t).val('');
                    comNotice.init('IP地址格式不正确')
                }
            }
        },
        addYm: function (t) {
            var _val = $(t).val(), $li = $(t).parent('li');
            cyb.add.d.scopeJson.ym='';
            if(_val!=''){
                if (Iy.isYm(_val)) {
                    $li.empty().append('<a href="javascript:;" onclick="cyb.add.btn.del(this,2)" class="btn-del"><i class="ico ico-clear"></i></a><div class="ms-item">' + _val + '</div>');
                    cyb.add.d.scopeJson.ym=_val;
                } else {
                    cyb.add.d.scopeJson.ym='';
                    $(t).val('');
                    comNotice.init('域名格式不正确')
                }
            }
        },
        addUrl: function (t) {
            var _val = $(t).val(), $li = $(t).parent('li');
            cyb.add.d.scopeJson.url='';
            if(_val!=''){
                _val = Iy.isHttp(_val);
                if (Iy.isUrl(_val)) {
                    $li.empty().append('<a href="javascript:;" onclick="cyb.add.btn.del(this,3)" class="btn-del"><i class="ico ico-clear"></i></a><div class="ms-item">' + _val + '</div>');
                    cyb.add.d.scopeJson.url=_val;
                } else {
                    cyb.add.d.scopeJson.url='';
                    $(t).val('');
                    comNotice.init('URL格式不正确')
                }
            }
        },
        toUpload: function () {
            $("#fileForm").ajaxSubmit({
                url: '/Cyberspace/main/fileUpload.do',
                type: "post",
                enctype: 'multipart/form-data',
                clearForm: true,
                dataType: 'json',
                beforeSend: function () {
                    $('.mc-adjunct').addClass('adjunctIng')
                },
                success: function (r) {
                    $('.mc-adjunct').removeClass('adjunctIng');
                    if (r.code == 1) {
                        cyb.add.d.files['name'].push(r.result[0]['fileName']);
                        cyb.add.d.files['path'].push(r.result[0]['filePath']);
                        var fileNames = cyb.add.d.files['name'].join(',');
                        $('.fileAllName').text(fileNames);
                        $('input[name="fileNames"]').val(fileNames);
                        $('input[name="filePaths"]').val(cyb.add.d.files['path'].join(','));
                    } else {
                        comNotice.init(r.msg || 'Error');
                    }
                },
                error: function () {
                    $('.mc-adjunct').removeClass('adjunctIng');
                    comNotice.init("Error File");
                }
            });
        },
        back: function () {
            $('.sec-header').empty().append($('#headerAdd').html());
            $('.mh-bd').text(cyb.add.d.infoType == 1 ? "信息新增" : (cyb.add.d.infoType == 2 ? "风险新增" : "事件新增"));
            var sJson = cyb.add.d.scopeJson;
            sJson.eDesc = $('textarea[name="yxTextarea"]').val();
            cyb.common.toExit('mod-create', 'mod-scope');
            var ii=[{ip:sJson['ip'],domainName:sJson['ym'],url:sJson['url']}];
            $('input[name="infrastructure_information"]').val(JSON.stringify(ii));
            $('input[name="influenceHarm"]').val(sJson.eDesc);
            $('input[name="regionIDs"]').val(cyb.add.d.hasAreaCk.join(','));
            $('input[name="industryIDs"]').val(cyb.add.d.hasIndustryCk.join(','));
        },
        back2: function (name) {
            var na = [];
            $.each($('.smc-bd').find('.checked'), function (i, v) {
                na.push($(v).data('id'))
            });
            cyb.add.d[name] = na;
            $('.sec-header').empty().append($('#headerScope').html());
            cyb.common.toExit('mod-scope', 'mod-scList');
        },
        getArea: function () {
            if (cyb.add.d.hasArea) {
                toArea();
            } else {
                IyData.getDomainTree(function (r) {
                    cyb.add.d.hasArea = true;
                    cyb.add.d.areaList = r;
                    toArea();
                });
            }
            function toArea() {
                $('.sec-header').empty().append($('#headerArea').html());
                $('.sec-body').append(JsTpl().render(cyb.add.d.areaList, 'scList1'));
                cyb.common.toJoin('mod-scope', 'mod-scList');
                $.each(cyb.add.d.hasAreaCk, function (i, hid) {
                    $('.mod-scList').find('li[data-id="' + hid + '"]').addClass('checked');
                });
            }
        },
        getIndustry: function () {
            if (cyb.add.d.hasIndustry) {
                toIndustry();
            } else {
                IyData.getIndustryTree(function (r) {
                    cyb.add.d.hasIndustry = true;
                    cyb.add.d.industryList = r;
                    toIndustry();
                });
            }
            function toIndustry() {
                $('.sec-header').empty().append($('#headerIndustry').html());
                $('.sec-body').append(JsTpl().render(cyb.add.d.industryList, 'scList2'));
                cyb.common.toJoin('mod-scope', 'mod-scList');
                $.each(cyb.add.d.hasIndustryCk, function (i, hid) {
                    $('.mod-scList').find('li[data-id="' + hid + '"]').addClass('checked');
                });
            }
        },
        join: function (type) {
            sessionStorage.setItem('infoType', type);
            cyb.init.btn.toAddClose();
            window.location.hash = "#Add";
        }
    }
};
cyb.add.btn.i();

cyb.addHome = {
    d: {
        isAddHomeReady: false,
        isTab: 1,
        page_0: 1,
        page_1: 1
    },
    v: function () {
        cyb.add.reset();//重置上报数据
        if (cyb.add.d.isAddPage) {
            if (cyb.addHome.d.isAddHomeReady) {
                $('.sec-header').empty().append($('#headerAddHome').html());
                cyb.common.toExit('mod-addHome', 'mod-create');
                if (cyb.add.d.isPull) {
                    cyb.addHome.refresh(cyb.addHome.d.$touch);
                }
            } else {
                this.k('mod-create');
            }
        } else if (cyb.desc.d.isDescPage) {
            if (cyb.addHome.d.isAddHomeReady) {
                $('.sec-header').empty().append($('#headerAddHome').html());
                cyb.common.toExit('mod-addHome', 'iy-desc');
            } else {
                this.k('iy-desc');
            }
        } else {
            if (cyb.addHome.d.isAddHomeReady) {
                this.j();
            } else {
                if (cyb.init.d.isHomeReady) {
                    this.i();
                } else {
                    this.j();
                }
            }
        }
        cyb.add.d.isAddPage = false;
        cyb.add.d.isPull = false;
    },
    k: function (pageDel) {
        var sVal = sessionStorage.getItem('urlVal');
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        cyb.init.d.userID=cyb.init.d.userInfo['createUserInfo']['linkdoodID'];
        //填充静态
        $('.sec-header').empty().append($('#headerAddHome').html());
        $('.sec-body').append($('#addHome').html());
        $('.mod-addHome').css('left', "-45%");
        cyb.common.toExit('mod-addHome', pageDel);
        cyb.addHome.d.isAddHomeReady = true;
        this.touch();
    },
    i: function () {
        var sVal = sessionStorage.getItem('urlVal');
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        cyb.init.d.userID=cyb.init.d.userInfo['createUserInfo']['linkdoodID'];
        //填充静态
        $('.sec-header').empty().append($('#headerAddHome').html());
        $('.sec-body').append($('#addHome').html());

        cyb.common.toJoin('iy-home', 'iy-secPage');
        cyb.addHome.d.isAddHomeReady = true;
        this.touch();

    },
    j: function () {
        var sVal = sessionStorage.getItem('urlVal');
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        cyb.init.d.userID=cyb.init.d.userInfo['createUserInfo']['linkdoodID'];
        //填充静态
        $('.sec-header').empty().append($('#headerAddHome').html());
        $('.sec-body').append($('#addHome').html());
        $('.iy-secPage').css('left', 0);
        cyb.addHome.d.isAddHomeReady = true;
        this.touch();
    },
    reset: function () {
        cyb.addHome.d.isTab = 1;
        cyb.addHome.d.page_0 = 1;
        cyb.addHome.d.page_1 = 1;
        cyb.addHome.d['loadList0'] = false;
        cyb.addHome.d['loadList1'] = false;
        cyb.addHome.d['loadError0'] = false;
        cyb.addHome.d['loadError1'] = false;
        cyb.addHome.d['loadIngList'] = false;
        cyb.addHome.d['loadEndList'] = false;
        cyb.addHome.d.isAddHomeReady = false;//取消上报首页标记
    },
    refresh: function (me, c) {
        cyb.addHome.d.page_0 = 1;
        cyb.addHome.d.page_1 = 1;
        cyb.addHome.d['loadList0'] = false;
        cyb.addHome.d['loadList1'] = false;
        cyb.addHome.d['loadError0'] = false;
        cyb.addHome.d['loadError1'] = false;
        cyb.addHome.d['loadIngList'] = false;
        cyb.addHome.d['loadEndList'] = false;
        cyb.add.d.isPull = false;
        //拉取我的上报
        IyData.getList2(1, function (r) {
            $('.aList-end-list').empty().append(JsTpl().render(r, 'myListItem'));
        }, me, 1);
        c ? c() : "";
    },
    touch: function () {
        cyb.addHome.d.$touch = $('.aList-scroll').dropload({
            scrollArea: $('.aContent'),
            domDown: {
                domClass: 'addHomeDown'
            },
            loadUpFn: function (me) {
                cyb.addHome.refresh(me, function () {
                    me.resetload();
                });
            },
            loadDownFn: function (me) {
                switch (cyb.addHome.d.isTab) {
                    case 1:
                        if (!cyb.addHome.d['loadList1'] && !cyb.addHome.d['loadError1'] && !cyb.addHome.d['loadEndList']) {
                            cyb.addHome.d['loadEndList'] = true;
                            IyData.getList2(1, function (r) {
                                $('.aList-end-list').append(JsTpl().render(r, 'myListItem'));
                                cyb.addHome.d['loadEndList'] = false;
                            }, me, cyb.addHome.d.page_1)
                        }
                        break;
                }
            },
            threshold: 50
        });
    },
    btn: {
        i: function () {
            this.view()
        },
        view: function () {
            IyBaseFun.e.$Body.on('click', '.aTab a', function () {
                if (!$(this).hasClass('active')) {
                    $(this).addClass('active').siblings().removeClass('active');
                    var idx = $(this).index();
                    cyb.report.d.isTab = idx;
                    $('.aContent').find('.aList-box').eq(idx).addClass('active').siblings().removeClass('active');
                    if (!cyb.addHome.d['loadList' + idx]) {
                        cyb.addHome.d.$touch.unlock();//解锁
                        cyb.addHome.d.$touch.noData(false);
                    } else {
                        cyb.addHome.d.$touch.lock('down');//锁
                        cyb.addHome.d.$touch.noData();
                    }
                    cyb.addHome.d.$touch.resetload();
                }
            });
        },
        toAdd: function () {
            cyb.init.btn.getEvent().stopPropagation();
            IyBaseFun.e.$Body.addClass('noScroll').append($('#addList').html());
            setTimeout(function () {
                $('.addList-tip').addClass('show');
            }, 10);
        },
        back: function () {
            $('.sec-header').empty().append($('#headerAddHome').html());
            cyb.common.toExit('mod-addHome', 'mod-create');
            if (cyb.add.d.isPull) {
                cyb.addHome.refresh(cyb.addHome.d.$touch);
            }
            //重置数据
            cyb.add.reset();
        },
        happenTime: function () {
            var opt = {}, ipt = $('input[name="happenDate"]');
            var t = new Date();
            var currYear = t.getFullYear();
            opt.date = {preset: 'date'};
            opt.datetime = {preset: 'date'};
            opt.time = {preset: 'time'};
            opt.default = {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                dateFormat: 'yy-mm-dd',
                lang: 'zh',
                endYear: currYear
            };
            ipt.mobiscroll($.extend(opt['datetime'], opt['default']));
        },
        initTime: function () {
            var opt = {}, ipt = $('.ipt-feedback');
            var t = new Date();
            var currYear = t.getFullYear() - 1;
            opt.date = {preset: 'date'};
            opt.datetime = {preset: 'date'};
            opt.time = {preset: 'time'};
            opt.default = {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                dateFormat: 'yyyy-mm-dd',
                lang: 'zh',
                startYear: currYear, //开始年份
                endYear: currYear + 10 //结束年份
            };
            ipt.mobiscroll($.extend(opt['datetime'], opt['default']));
        },
        toEdit: function (id, type) {
            $('.sec-header').empty().append($('#headerEdit').html());
            $('.sec-body').append($('#createPage').html());
            if (type != 1) {
                cyb.add.d.selectList = {
                    list: [],
                    code: [],
                    sub: {}//子事件列表
                };
                IyData.getType(type);
            }
            cyb.common.toJoin('mod-addHome', 'mod-create', function () {
                IyData.getDesc2(id, function (r, od) {
                    r.phone = cyb.addHome.d.phone;
                    if (type == 2) {
                        r.gradeName = cyb.desc.d.grade1[r.grade];
                    }
                    if (type == 3) {
                        r.gradeName = cyb.desc.d.grade2[r.grade];
                        cyb.addHome.btn.initTime();
                    }
                    $('.mod-create').append(JsTpl().render(r, 'edit_' + type));
                    cyb.addHome.btn.happenTime();
                    if ('type' in od) {
                        $.each(od['type'], function (m, n) {
                            var li = $('li[data-mt="' + n + '"]');
                            li.addClass('checked');
                            li.find('input').prop("checked", true);
                        });
                    }
                });
            });
        },
        del: function (id) {
            IyData.delInfo(id);
        }
    }
};
cyb.addHome.btn.i();

cyb.toList = {
    d: {
        isListReady: false,
        isTab: 0,//0:信息,1：事件,2:预警,3:每日0报告
        page: 1,//页数
        form_0: {},//信息筛选条件
        form_1: {},
        form_2: {},
        form_3: {},
        oldForm: {}//记录筛选前的表单
    },
    reset: function () {
        cyb.toList.d.page = 1;
        cyb.toList.d.form_0 = {};
        cyb.toList.d.form_1 = {};
        cyb.toList.d.form_2 = {};
        cyb.toList.d.form_3 = {};
        cyb.toList.d.loadError = false;
        cyb.toList.d.loadListEnd = false;
        cyb.toList.d.loadIng = false;
    },
    v: function () {
        if (cyb.desc.d.isDescPage) {
            if (cyb.toList.d.isListReady) {
                $('.sec-header').empty().append($('#listHeader').html());
                cyb.common.toExit('iy-work', 'iy-desc');//退出详情
            } else {
                this.k('iy-desc');
            }
        } else if (cyb.sum.d.isSumPage) {
            if (cyb.toList.d.isListReady) {
                $('.sec-header').empty().append($('#listHeader').html());
                cyb.common.toExit('iy-work', 'mod-sum');//退出报告
            } else {
                this.k('mod-sum');
            }
        } else {
            if (cyb.toList.d.isListReady) {
                this.j();
            } else {
                if (cyb.init.d.isHomeReady) {
                    this.i();
                } else {
                    this.j();
                }
            }
        }
        cyb.desc.d.isDescPage = false;
        cyb.sum.d.isSumPage = false;
        cyb.sum.reset();
    },
    i: function () {
        var sVal = sessionStorage.getItem('urlVal');
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        cyb.init.d.userID=cyb.init.d.userInfo['createUserInfo']['linkdoodID'];
        //填充静态
        $('.sec-header').empty().append($('#listHeader').html());
        $('.sec-body').append($('#listPage').html());
        cyb.common.toJoin('iy-home', 'iy-secPage');
        this.touch();
        cyb.toList.d.isListReady = true;
    },
    k: function (pageDel) {
        var sVal = sessionStorage.getItem('urlVal');
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        cyb.init.d.userID=cyb.init.d.userInfo['createUserInfo']['linkdoodID'];
        //填充静态
        $('.sec-header').empty().append($('#listHeader').html());
        $('.sec-body').append($('#listPage').html());
        $('.iy-work').css('left', "-45%");
        cyb.common.toExit('iy-work', pageDel);//退出详情
        this.touch();
        cyb.toList.d.isListReady = true;
    },
    j: function () {
        var sVal = sessionStorage.getItem('urlVal');
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        cyb.init.d.userID=cyb.init.d.userInfo['createUserInfo']['linkdoodID'];
        //填充静态
        $('.sec-header').empty().append($('#listHeader').html());
        $('.sec-body').append($('#listPage').html());
        $('.iy-secPage').css('left', 0);
        this.touch();
        cyb.toList.d.isListReady = true;
    },
    touch: function () {
        cyb.toList.d.$touch = $('.list-scroll-box').dropload({
            scrollArea: $('.mod-list'),
            domDown: {
                domClass: 'listDown'
            },
            loadUpFn: function (me) {
                cyb.toList.toPull(cyb.toList.d.isTab, '', function () {
                    me.resetload();
                })
            },
            loadDownFn: function (me) {
                if (!cyb.toList.d['loadListEnd'] && !cyb.toList.d['loadError'] && !cyb.toList.d['loadIng']) {
                    cyb.toList.d['loadIng'] = true;
                    var box = $('.mod-list .list-box');
                    switch (cyb.toList.d.isTab) {
                        case 0:
                            cyb.toList.d.form_0.page = cyb.toList.d.page;
                            IyData.getList(cyb.toList.d.form_0, function (r) {
                                box.append(JsTpl().render(r, 'listItem'));
                                cyb.toList.d['loadIng'] = false;
                            }, me);
                            break;
                        case 1:
                            cyb.toList.d.form_1.page = cyb.toList.d.page;
                            IyData.getAllEventList(cyb.toList.d.form_1, function (r) {
                                box.append(JsTpl().render(r, 'EvenListItem'));
                                cyb.toList.d['loadIng'] = false;
                            }, me);
                            break;
                        case 2:
                            cyb.toList.d.form_2.page = cyb.toList.d.page;
                            IyData.getAllRiskList(cyb.toList.d.form_2, function (r) {
                                box.append(JsTpl().render(r, 'RiskListItem'));
                                cyb.toList.d['loadIng'] = false;
                            }, me);
                            break;
                        case 3:
                            cyb.toList.d.form_3.page = cyb.toList.d.page;
                            IyData.getAllReport(cyb.toList.d.form_3, function (r) {
                                box.append(JsTpl().render(r, 'reportListItem'));
                                cyb.toList.d['loadIng'] = false;
                            }, me);
                            break;
                    }
                }
            },
            threshold: 50
        });
    },
    toPull: function (type, isScreen, c) {
        if(isScreen){
            cyb.toList.d.page=1;
            cyb.toList.d.form_0.page=1;
            cyb.toList.d.form_1.page=1;
            cyb.toList.d.form_2.page=1;
            cyb.toList.d.form_3.page=1;
        }else{//重置表单
            this.reset()
        }
        var box = $('.mod-list .list-box');
        box.empty();
        switch (type) {
            case 0:
                IyData.getList(cyb.toList.d.form_0, function (r) {
                    box.append(JsTpl().render(r, 'listItem'));
                }, cyb.toList.d.$touch);
                break;
            case 1:
                IyData.getAllEventList(cyb.toList.d.form_1, function (r) {
                    box.append(JsTpl().render(r, 'EvenListItem'));
                }, cyb.toList.d.$touch);
                break;
            case 2:
                IyData.getAllRiskList(cyb.toList.d.form_2, function (r) {
                    box.append(JsTpl().render(r, 'RiskListItem'));
                }, cyb.toList.d.$touch);
                break;
            case 3:
                IyData.getAllReport(cyb.toList.d.form_3, function (r) {
                    box.append(JsTpl().render(r, 'reportListItem'));
                }, cyb.toList.d.$touch);
                break
        }
        c ? c() : ''
    },
    btn: {
        i: function () {
            this.view()
        },
        view: function () {
            IyBaseFun.e.$Body.on('click', '.st-btn', function (e) {
                e.stopPropagation();
                var ms = $('.mod-screen');
                if (ms.hasClass('screen-infoType')) {
                    ms.removeClass('screen-infoType')
                } else {
                    ms.addClass('screen-infoType')
                }
            });
            IyBaseFun.e.$Body.on('click', function () {
                $('.mod-screen').removeClass('screen-infoType');
            });
            IyBaseFun.e.$Body.on('click', '.ws-bg', function () {
                cyb.toList.btn.sureForm();
            });
            IyBaseFun.e.$Body.on('click', '.btn-screen', function (e) {
                e.stopPropagation();
                var screen = cyb.toList.d.isTab == 0 ? 'screen_0' : cyb.toList.d.isTab == 3 ? 'screen_3' : 'screen_1';
                $('.ws-scroll').empty().append(JsTpl().render(cyb.toList.d['form_' + cyb.toList.d.isTab], screen));
                cyb.toList.d.oldForm = $.extend(true, {}, cyb.toList.d['form_' + cyb.toList.d.isTab]);
                $('.mod-screen').removeClass('screen-infoType');
                $('.work-screen').addClass('ws-show');
                $('.type-item[data-st="' + cyb.toList.d.oldForm["infoType"] + '"]').addClass('active');
                cyb.toList.btn.initTime();
            });
            IyBaseFun.e.$Body.on('input', '.search-input', function () {
                var sp = $('.search-ipt'), cd = cyb.toList.d['form_' + cyb.toList.d.isTab];
                if ($(this).val() != "") {
                    cd['title'] = $(this).val();
                    sp.addClass('search-focus');
                } else {
                    delete cd['title'];
                    sp.removeClass('search-focus');
                }
            });
            IyBaseFun.e.$Body.on('click', '.search-clear', function () {
                $('.search-input').val("");
                delete cyb.toList.d['form_' + cyb.toList.d.isTab]['title'];
                $('.search-ipt').removeClass('search-focus');
            });
        },
        initTime: function () {
            var opt = {}, ipt = $('.ipt-time');
            var t = new Date();
            var currYear = t.getFullYear() - 1;
            opt.date = {preset: 'date'};
            opt.datetime = {preset: 'date'};
            opt.time = {preset: 'time'};
            opt.default = {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                dateFormat: 'yyyy-mm-dd',
                lang: 'zh',
                startYear: currYear, //开始年份
                endYear: currYear + 10 //结束年份
            };
            ipt.mobiscroll($.extend(opt['datetime'], opt['default']));
        },
        tab: function (type, t) {
            var _t = $(t), btn = $('.screen-tab .st-btn');
            _t.addClass('checked').siblings().removeClass('checked');
            btn.text(_t.text());
            cyb.toList.d.isTab = type;
            cyb.toList.toPull(type);
            $('.btn-screen').removeClass('hasScreen');
        },
        screenExit: function () {
            $('.work-screen').addClass('ws-hide');
            setTimeout(function () {
                $('.work-screen').removeClass('ws-hide ws-show');
            }, 500);
        },
        resetForm: function () {
            cyb.toList.d['form_' + cyb.toList.d.isTab] = {};
            $('.search-input').val("");
            $('.ipt-time').val("");
            $('.screen-type .type-item ').removeClass('checked');
            $('.btn-screen').removeClass('hasScreen');
        },
        sureForm: function () {
            var old = cyb.toList.d.oldForm, nForm = cyb.toList.d['form_' + cyb.toList.d.isTab];
            var sTime = $('.ipt-time[name="startTime"]').val(), eTime = $('.ipt-time[name="endTime"]').val();
            if (sTime != '') {
                nForm['startTime'] = sTime
            } else {
                delete nForm['startTime']
            }
            if (eTime != '') {
                nForm['endTime'] = eTime
            } else {
                delete nForm['endTime']
            }
            if (old['title'] == nForm['title'] && old['startTime'] == nForm['startTime'] && old['endTime'] == nForm['endTime']) {
                cyb.toList.btn.screenExit();
            } else {
                $('.btn-screen').addClass('hasScreen');
                cyb.toList.btn.screenExit();
                cyb.toList.toPull(cyb.toList.d.isTab, 1);
            }
        },
        toReportDesc: function (id) {
            sessionStorage.setItem('sumID', id);
            window.location.hash = '#Sum';
        }
    }
};
cyb.toList.btn.i();

cyb.sum = {
    d: {
        isSumPage: false,
        pageNum: 1,
        isTab: 0
    },
    reset: function () {
        cyb.sum.d.isTab = 0;
        cyb.sum.d.pageNum = 1;
        cyb.sum.d['loadListEnd'] = false;
        cyb.sum.d['loadError'] = false;
        cyb.sum.d['loadIng'] = false;
    },
    i: function (id) {
        var sVal = sessionStorage.getItem('urlVal');
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        cyb.init.d.userID=cyb.init.d.userInfo['createUserInfo']['linkdoodID'];
        this.d.id = id;

        $('.sec-header').empty().append($('#headerReportSum').html());
        $('.sec-body').append($('#sumPage').html());
        cyb.sum.d.isSumPage = true;
        cyb.common.toJoin('iy-work', 'mod-sum', function () {
            IyData.getReportDesc3(id, function (r) {
                $('.sum-hd').append(JsTpl().render(r, 'sumHd'));
            });
        });
        this.touch(id);
        this.scroll();
    },
    j: function (id) {
        var sVal = sessionStorage.getItem('urlVal');
        cyb.init.d.userInfo = JSON.parse(sVal)['userInfo'];
        cyb.init.d.userID=cyb.init.d.userInfo['createUserInfo']['linkdoodID'];
        this.d.id = id;

        $('.sec-header').empty().append($('#headerReportSum').html());
        $('.sec-body').append($('#sumPage').html());
        $('.iy-secPage').css('left', 0);
        $('.mod-sum').css('left', 0);
        cyb.sum.d.isSumPage = true;
        IyData.getReportDesc3(id, function (r) {
            $('.sum-hd').append(JsTpl().render(r, 'sumHd'));
        });
        this.touch(id);
        this.scroll();
    },
    touch: function (id) {
        cyb.sum.d.$touch = $('.sum-scroll').dropload({
            scrollArea: $('.mod-sum'),
            domDown: {
                domClass: 'sumDown'
            },
            loadDownFn: function (me) {
                if (!cyb.sum.d['loadListEnd'] && !cyb.sum.d['loadError'] && !cyb.sum.d['loadIng']) {
                    cyb.sum.d['loadIng'] = true;
                    var opts = {id: id};
                    switch (cyb.sum.d.isTab) {
                        case 0:
                            opts.flag = 0;
                            opts.page = cyb.sum.d.pageNum;
                            IyData.getReportDesc2(opts, function (r) {
                                $('.sum-box').append(JsTpl().render(r, 'sItem0'));
                                cyb.sum.d['loadIng'] = false;
                            }, me);
                            break;
                        case 1:
                            opts.flag = 1;
                            opts.page = cyb.sum.d.pageNum;
                            IyData.getReportDesc2(opts, function (r) {
                                $('.sum-box').append(JsTpl().render(r, 'sItem1'));
                                cyb.sum.d['loadIng'] = false;
                            }, me);
                            break;
                    }
                }
            },
            threshold: 50
        });
    },
    toPull: function (type) {
        cyb.sum.d['loadListEnd'] = false;
        cyb.sum.d['loadError'] = false;
        cyb.sum.d['loadIng'] = false;
        cyb.sum.d.pageNum = 1;
        var opts = {
            id: cyb.sum.d.id,
            reportdate: cyb.sum.d.time
        }, box = $('.sum-box');
        box.empty();
        switch (type) {
            case 0:
                opts.flag = 0;
                IyData.getReportDesc2(opts, function (r) {
                    box.append(JsTpl().render(r, 'sItem0'));
                }, cyb.sum.d.$touch);
                break;
            case 1:
                opts.flag = 1;
                IyData.getReportDesc2(opts, function (r) {
                    box.append(JsTpl().render(r, 'sItem1'));
                }, cyb.sum.d.$touch);
                break;
        }
    },
    tab: function (t) {
        var _t = $(t), ta = _t.parent('li'), idx = ta.index();
        if (!ta.hasClass('active')) {
            ta.addClass('active').siblings().removeClass('active');
            cyb.sum.d.isTab = idx;
            cyb.sum.toPull(idx);
        }
    },
    scroll: function () {
        $('.mod-sum').scroll(function () {
            var $ib = $('.sum-bd');
            var bt = $ib.position().top;
            if ($('.mod-sum').scrollTop() >= bt) {
                $ib.addClass('sum-fixed');
            } else {
                $ib.removeClass('sum-fixed');
            }
        })
    }
};

$(window).on('hashchange', function () {
    switch (window.location.hash) {
        case '#Desc'://详情界面
            var descID = sessionStorage.getItem('descID');
            if (!!descID) {
                cyb.desc.i(descID);
            } else {
                window.location.hash = "";
                return;
            }
            break;
        case '#List'://工作情况
            cyb.toList.v();
            break;
        case '#Report':
            cyb.report.i();
            break;
        case '#AddHome':
            cyb.addHome.v();
            break;
        case "#Add":
            cyb.add.i();
            break;
        case "#Sum":
            var sumID = sessionStorage.getItem('sumID');
            if (!!sumID) {
                cyb.sum.i(sumID);
            } else {
                window.location.hash = "";
                return;
            }
            break;
        case '':
            cyb.init.backHome();
            break;
        default:
            cyb.init.backHome();
            break;
    }
});
$(document).ready(function () {
    var sVal = sessionStorage.getItem('urlVal'), hash = window.location.hash;
    hash = hash.split('?')[0];
    switch (hash) {
        case '':
            cyb.init.i();
            break;
        case '#Desc'://详情页面
            var descID = sessionStorage.getItem('descID');
            if (!!descID) {
                cyb.desc.j(descID);
            } else {
                window.location.hash = "";
                return;
            }
            break;
        case '#List'://工作情况
            if (!!sVal) {
                cyb.toList.v();
            } else {
                window.location.hash = '';
            }
            break;
        case '#Report':
            if (!!sVal) {
                cyb.report.j();
            } else {
                window.location.hash = ''
            }
            break;
        case '#reportDesc':
            cyb.report.desc2.i();//模版详情
            break;
        case '#AddHome':
            if (!!sVal) {
                cyb.addHome.v();
            } else {
                window.location.hash = ''
            }
            break;
        case '#Add':
            if (!!sVal && !!sessionStorage.getItem('infoType')) {
                cyb.add.j();
            } else {
                window.location.hash = ''
            }
            break;
        case "#Sum":
            var sumID = sessionStorage.getItem('sumID');
            if (!!sumID) {
                cyb.sum.j(sumID);
            } else {
                window.location.hash = "";
                return;
            }
            break;
        default:
            cyb.init.i();
            break;
    }
});

